package com.muyu.controller;

import java.util.Arrays;
import java.util.List;

import com.muyu.domain.req.WarnStrategyReq;
import com.muyu.domain.resp.WarnStrategyResp;
import com.muyu.service.WarnStrategyService;
import jakarta.servlet.http.HttpServletResponse;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.domain.WarnStrategy;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;
import org.springframework.validation.annotation.Validated;
import com.muyu.common.core.web.page.TableDataInfo;

/**
 * 预警策略Controller
 *
 * @author sx
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/strategy")
public class WarnStrategyController extends BaseController
{
    @Resource
    private WarnStrategyService warnStrategyService;

    /**
     * 查询预警策略列表
     */
    @PostMapping("/selectWarnStrategyList")
    public Result selectWarnStrategyList(@RequestBody WarnStrategyReq warnStrategyReq)
    {
      return Result.success(warnStrategyService.selectWarnStrategyList(warnStrategyReq));
    }


    /**
     * 获取预警策略详细信息
     */
    @GetMapping( "selectById/{id}")
    public Result selectById(@PathVariable("id") Long id)
    {
        return success(warnStrategyService.selectWarnStrategyById(id));
    }

    /**
     * 新增预警策略
     */
    @PostMapping("/addWarnStrategy")
    public Result addWarnStrategy(@RequestBody WarnStrategy warnStrategy)
    {
        Integer i = warnStrategyService.addWarnStrategy(warnStrategy);
        return i>0?Result.success():Result.error();
    }

    /**
     * 修改预警策略
     */
    @PostMapping("/updWarnStrategy")
    public Result updWarnStrategy(@RequestBody WarnStrategy warnStrategy)
    {
        Integer i = warnStrategyService.updWarnStrategy(warnStrategy);
        return i>0?Result.success():Result.error();
    }

    /**
     * 删除预警策略
     */
	@DeleteMapping("deleteWarnStrategy/{id}")
    public Result deleteWarnStrategy(@PathVariable("id") Long id)
    {
        Integer i = warnStrategyService.deleteWarnStrategy(id);
        return i>0?Result.success():Result.error();
    }



    /**
     * 根据车辆类型ID查询策略
     */
    @GetMapping("/selectListByCarType/{carTypeId}")
    public Result selectListByCarType(@PathVariable("carTypeId") Long carTypeId) {
        return Result.success(warnStrategyService.selectListByCarType(carTypeId));
    }
}
